home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / TOUCHE.ASM < prev    next >
Assembly Source File  |  1986-06-01  |  19KB  |  653 lines

  1.     page 58,132
  2.     title TOUCHE -- A File Date Maintenance Utility
  3.     name TOUCHE
  4.  
  5. comment    *
  6.     
  7.     This program will change the date/time stamp of all files on its 
  8.     command line to the current date and time.
  9.     
  10.     See TOUCHE.DOC for instructions on how to use this program.
  11.     
  12.     Copyright (c) 1986    Raymond Moon   ALL RIGHTS RESERVED
  13.     
  14.     *
  15.  
  16. ;----------------------------
  17. ;    Define the various macros used in this program.
  18.     
  19. @CLOSE    macro    FH            ;; DOS 2.0+ Close File/Device Macro
  20.     mov    bx,FH            ; Load File Handle into BX
  21.     mov    ah,3eh            ; Request DOS close File Handle
  22.     int    21h            ; Call PC-DOS
  23.     endm
  24.  
  25. @ENTRY    macro                ;; Standard Procedure Entry Logic
  26.     push    bp            ; Save BP
  27.     mov    bp,sp            ; Establish stack addressability
  28.     endm
  29.  
  30. @EXIT    macro    RTNCODE            ;; Terminate program with return code
  31.     mov    ax,4c&RTNCODE&h        ; Request term with return code
  32.     int    21h            ; Call PC-DOS
  33.     endm
  34.  
  35. @GETDATE macro                ;; Get Current Date Macro
  36.     mov    ah,2ah            ; Request DOS get current date
  37.     int    21h            ; Call PC-DOS
  38.     endm
  39.         
  40. @GETTIME macro                ;; Get Current Time Macro
  41.     mov    ah,2ch            ; Request DOS get current time
  42.     int    21h            ; Call PC-DOS
  43.     endm
  44.  
  45. @OPEN    macro    FILESPEC,MODE        ;; DOS 2.0+ Open File Macro
  46.     lea    dx,FILESPEC        ; Load addr of FILESPEC in DX
  47.     mov    ax,3D0&MODE&h        ; Request DOS open file with mode
  48.     int    21h            ; Call PC-DOS
  49.     endm
  50.     
  51. @WRITE    macro    STRING,FH        ;; DOS 2.0+ Write to File Macro
  52.     lea    dx,STRING        ; Load String addr in DX
  53.     mov    cx,STRING&_LEN        ; Load String Length in CX
  54.     mov    bx,FH            ; Load File Handle in BX
  55.     mov    ah,40h            ; Request DOS write to file/device
  56.     int    21h            ; Call PC-DOS
  57.     endm
  58.  
  59. ;----------------------------
  60. ;    Define various equates used in this program
  61.  
  62.     STDOUT    equ    1
  63.     STDERR    equ    2
  64.     TAB    equ    9
  65.         BLNK    equ     20h
  66.     LF    equ    0ah
  67.     CR    equ    0dh
  68.  
  69. ;----------------------------
  70. ;    Define the group and segments so that all will reside in one 64K
  71. ;    physical segment.
  72.  
  73. GRP    group    CSEG,DTA,DSEGB,DSEGA        ; All segments in same segment
  74.     assume    cs:GRP,ds:GRP,es:GRP,ss:GRP
  75.     
  76. DSEGB    segment byte public 'STRING'
  77.  
  78.     public LOGO, DOS_ERR, NOT_FOUND, TOUCHED, PROPER_USE, CANT
  79.     
  80. LOGO    db    'TOUCHE -- A File Date Maintenance Utility V1.00',CR,LF
  81.     db    'Copyright 1986 - MoonWare',CR,LF,LF
  82. LOGO_LEN equ    $ - LOGO
  83. DOS_ERR db    CR,LF,LF,'TOUCHE:  Need DOS 2.0+'
  84. NOT_FOUND db    ' -- Not Found',CR,LF
  85. NOT_FOUND_LEN equ $ - NOT_FOUND
  86. TOUCHED db    ' -- Touched',CR,LF
  87. TOUCHED_LEN equ $ - TOUCHED
  88. CANT    db    ' -- Cannot Touch',CR,LF
  89. CANT_LEN equ    $ - CANT
  90. PROPER_USE db    CR,LF,'TOUCHE:  Nothing to do.',CR,LF,LF,'Use:',CR,LF,LF,TAB
  91.     db    'touche file1.ext file2.ext . . . fileN.ext',CR,LF,LF,TAB
  92.     db    'Drive, Path, and Wildcards allowed in file names.',CR,LF,LF
  93. PROPER_USE_LEN equ $ - PROPER_USE
  94.     db    '***** 30 May 1986 -- Raymond Moon *****'
  95. DSEGB    ends
  96.  
  97. DSEGA    segment byte public 'DATA'
  98.     public    pDOS_ERR
  99. pDOS_ERR dw    offset GRP:DOS_ERR
  100. DSEGA    ends
  101.  
  102. ;----------------------------
  103. ;    Use 'Segment At' to create variable to access the information
  104. ;    contained in the DTA after First Find/Next Find DOS Function
  105. ;    call is used.
  106.     
  107. DTA    segment at 00h
  108.     public  FILENAME
  109.     
  110.     org    80h
  111.     
  112. RESERVED_DOS    db    21 dup (?)
  113. DTA_ATTRIB    db    ?
  114. DTA_TIME    dw    ?
  115. DTA_DATE    dw    ?
  116. DTA_SIZE_LO    dw    ?
  117. DTA_SIZE_HI    dw    ?
  118. FILENAME    db    13 dup (?)
  119. DTA    ends
  120.  
  121. ;----------------------------
  122. ;    Define structure to address argc and *argv[].
  123.  
  124. STACK_PARMS    struc
  125.     dw    ?,?            ; Saved BP & Return Address
  126. ARGC    dw    ?            ; Count of command line arguments
  127. ARGV    dw    ?            ; Address to command line arguments
  128. STACK_PARMS    ends
  129.  
  130.     
  131. CSEG    segment para public 'CODE'
  132.  
  133. ;-----------------------------
  134. ;    Define all procedures as public for debugging
  135.  
  136.     public MAIN, TOUCH_FILES, NOTHING_TO_DO, ISDOS2, FPUTS, STRCPY, STRLEN
  137.  
  138. ;-----------------------------
  139. ;    Define Command Line arguments located in the PSP
  140.  
  141.     org     80h
  142.     PARM_LEN db     ?
  143.     PARMS   db      127 dup(?)
  144.  
  145. ;-----------------------------
  146. ;    MAIN procedure parses the Command Line 
  147.  
  148.     org    100h            ; .COM file format
  149. MAIN    proc    far
  150.     push    pDOS_ERR        ; Pass addr of DOS_ERR
  151.     call    ISDOS2            ; Check to see if DOS is 2.0+ 
  152.     add    sp,2            ; Reset SP
  153.     cmp    PARM_LEN,0        ; Are there any Command Line arguments
  154.     jne    MN1            ; Yes, process them
  155.     call    NOTHING_TO_DO        ; No, go to Nothing_to_do 
  156. MN1:    xor    cx,cx            ; Null CX
  157.     push    cx            ; This ensures last *argv ends in NUL
  158.     mov    cl,PARM_LEN        ; Get # of bytes in Command Line
  159.     inc    cl            ; Increment CL to ensure round up
  160.     and    cx,0feh            ; Force an even count
  161.     mov    ax,sp            ; Get SP  
  162.     mov    bp,sp            ; Set BP to last byte of Cmd Ln
  163.     sub    ax,cx            ; Subtract PARM_LEN
  164.     mov    sp,ax            ; Reset SP, room on Stack
  165.     lea    si,PARMS        ; Load source addr in SI
  166.     mov    di,sp            ; Load destin addr in DI
  167.     cld                ; Ensure Direction Flag is up
  168.     rep    movsb            ; Move Command Line onto the Stack
  169.  
  170. ;-----------------------------
  171. ;    Convert all blanks in the Command Line to Nul
  172.  
  173.     mov    bx,bp            ; BX points to last byte of Cmd Ln
  174. MN2:    mov    al,[bx]            ; Get byte
  175.     cmp    al,BLNK            ; Is it a blank?
  176.     ja    MN3            ; No, go set up to get another
  177.     xor    al,al            ; Nul AX
  178.     mov    [bx],al            ; Store Nul in [BX]
  179. MN3:    dec    bx            ; BX point to next byte
  180.     cmp    bx,sp            ; Are we through yet?
  181.     jnb    MN2            ; No, go one mo' 'gin
  182.                     
  183. ;-----------------------------
  184. ;    Build *argv[].  argc kept in CX.  DX used as IN_WORD flag
  185.  
  186.     xor    cx,cx            ; Set CX (argc) to 0
  187.     xor    dx,dx            ; Set DX to NOT_INWORD
  188.     mov    bx,bp            ; BX point to last byte
  189.     mov    bp,sp            ; BP now points to Top of Stack
  190. MN4:    mov    al,[bx]            ; Get byte
  191.     cmp    al,0            ; Is it Nul?
  192.     jne    MN5            ; No, it is a char
  193.     cmp    dx,0            ; Was the last byte not a char?
  194.     je    MN6            ; Yes, go on with the processing
  195.     xor    dx,dx            ; No, it was a char.  Clear INWORD.
  196.     inc    cx            ; Increment argc
  197.     inc    bx            ; BX points to Cmd Ln arg
  198.     push    bx            ; Push addr onto stack
  199.     dec    bx            ; Reset BX
  200.     jmp    short MN6        ; Go set up for another byte
  201. MN5:    inc    dx            ; Set DX to INWORD     
  202. MN6:    dec    bx            ; BX point to next byte
  203.     cmp    bx,bp            ; Are we at the 1st byte yet?
  204.     jnb    MN4            ; No, go process another
  205.  
  206. ;-----------------------------
  207. ;    Set up for and call TOUCH_FILES
  208.  
  209.     push    cx            ; Push ARGC onto stack
  210.     call    TOUCH_FILES        ; Process files
  211. MAIN    endp
  212.  
  213. ;----------------------------
  214. ;    This procedure prints the string PROPER_USE then terminates the 
  215. ;    program.
  216.  
  217. NOTHING_TO_DO proc near
  218.     @WRITE    PROPER_USE,STDERR    ; Tell the user how to use TOUCH
  219.     @EXIT    01            ; Exit with return code of 1
  220. NOTHING_TO_DO endp
  221.  
  222. ;----------------------------
  223. ;    Process each filename one at a time.
  224.  
  225. TOUCH_FILES    proc near
  226.     @ENTRY                ; Std Entry Logic
  227.     sub    sp,75            ; Make room for automatic variables
  228.     
  229. TF_BASE equ    [bp - 75]        ; Automatic variable addressing base
  230.  
  231. TF_AUTO    struc                ; Automatic variable structure
  232. DATE    dw    ?
  233. TIME    dw    ?
  234. COUNT    dw    ?
  235. LENGTH    dw    ?
  236. FILE_HANDLE dw    ?
  237. PATH_END dw    ?
  238. FILESPEC db    63 dup (?)
  239. TF_AUTO    ends
  240.     
  241. ;----------------------------
  242. ;    Display logo
  243.  
  244.     @WRITE LOGO,STDOUT
  245.     
  246. ;----------------------------
  247. ;    Get the time and date.  Convert these into DOS file date/time stamp
  248. ;    format.
  249.  
  250.     @GETDATE            ; Get the DOS date
  251.     xor    ax,ax            ; Nul AX
  252.     sub    cx,1980            ; Convert #years into DOS file format
  253.     xchg    ch,cl            ; Move year into CH
  254.     shl    ch,1            ; Convert year into DOS file format
  255.     or    ah,ch            ; Move it into AX
  256.     xor    bx,bx            ; Nul BX
  257.     mov    bh,dh            ; Month into BX
  258.     shr    bx,1
  259.     shr    bx,1
  260.     shr    bx,1            ; Convert month into DOS file format
  261.     or    ax,bx            ; Move it into AX
  262.     or    al,dl            ; Move seconds into AX
  263.     mov    TF_BASE.DATE,ax        ; Save it
  264.     
  265. ;----------------------------
  266. ;    Get the time and convert it.
  267.  
  268.     @GETTIME            ; Get the DOS time
  269.     xor    ax,ax            ; Nul AX
  270.     xor    bx,bx            ; Nul BX
  271.     shl    ch,1
  272.     shl    ch,1
  273.     shl    ch,1            ; Convert hour into DOS file format
  274.     or    ah,ch            ; Move it into AX
  275.     mov    bh,cl            ; Move minutes into BH
  276.     shr    bx,1
  277.     shr    bx,1
  278.     shr    bx,1            ; Convert minutes into DOS file format
  279.     or    ax,bx            ; Move it into AX
  280.     or    al,dh            ; Move seconds into AX
  281.     mov    TF_BASE.TIME,ax        ; Save it
  282.     
  283. ;----------------------------
  284. ;    Set Count to zero.
  285.  
  286.     xor    ax,ax            ; Nul AX
  287.     mov    TF_BASE.COUNT,ax    ; Set count to zero
  288.     
  289. ;----------------------------
  290. ;    Process next file in command line.  Start by stripping off any drive
  291. ;    and path and save it in filespec.  Start b